//
//  MSRegisterInfoCell.m
//  MOSS
//
//  Created by apple on 2019/1/8.
//  Copyright © 2019年 apple. All rights reserved.
//

#import "MSRegisterInfoCell.h"

@interface MSRegisterInfoCell ()

@property (nonatomic, strong) UILabel *titleLab;

@end

@implementation MSRegisterInfoCell

+ (instancetype)createTableView:(UITableView *)tableView {
    MSRegisterInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"litcell"];
    cell.selectionStyle  = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor blackColor];

    [cell makeViews];
    
    return cell;
}

- (void)makeViews {
    if (self.accountBtn) {
        return;
    }
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(30);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(15);
    }];
    
    NSArray *titlearray = @[@"5000",@"10000",@"50000",@"100000"];
   
    int margin   = 15;
    int btnWidth = (SCREEN_WIDTH-75)/4.0;
   
    for (int i = 0; i < titlearray.count; i++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(margin*(i+1) + btnWidth*i,60,btnWidth,30)];
        btn.layer.borderWidth   = 1;
        btn.layer.cornerRadius  = 5;
        btn.layer.masksToBounds = YES;
        btn.layer.borderColor  = [UIColor colorWithHEX:maincolor].CGColor;
        btn.tag = i;
        [btn setTitle:titlearray[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [btn addTarget:self action:@selector(selectBtn:) forControlEvents:UIControlEventTouchUpInside];
       
        if (i == 0) {
            btn.layer.backgroundColor = [UIColor colorWithHEX:maincolor].CGColor;
            btn.selected    = YES;
            self.accountBtn = btn;
        }
        [self addSubview:btn];
    }

    [self.contentView addSubview:self.accountLab];
    [self.accountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(115);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(13);
    }];
}

- (void)selectBtn:(UIButton *)btn {
    if (!btn.isSelected) {
        self.accountBtn.selected = !self.accountBtn.selected;
        self.accountBtn.layer.backgroundColor = [UIColor colorWithHEX:@"181E2E"].CGColor;
       
        btn.selected = !btn.selected;
        btn.layer.backgroundColor = [UIColor colorWithHEX:maincolor].CGColor;

        self.accountBtn = btn;
        
        if (self.accountBlock) {
            self.accountBlock(btn.titleLabel.text);
        }
    }
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = [UIFont systemFontOfSize:15];
        _titleLab.textColor = [UIColor whiteColor];
        _titleLab.text = LocalizationKey(@"请输入数量:");
    }

    return _titleLab;
}

- (UILabel *)accountLab {
    if (!_accountLab) {
        _accountLab = [[UILabel alloc] init];
        _accountLab.font = [UIFont systemFontOfSize:15];
        _accountLab.textColor = [UIColor colorWithHEX:@"cbcbcb"];
        _accountLab.text = [NSString stringWithFormat:@"%@:0",LocalizationKey(@"Available balance")];
    }

    return _accountLab;
}



@end
